<template>
  <div class="filter-bar">
    <div class="filter-left">
      <span class="filter-label">选择时间</span>
      <input
        type="date"
        class="date-input"
        v-model="dateRange[0]"
        @change="$emit('date-change')"
      />
      <span>~</span>
      <input
        type="date"
        class="date-input"
        v-model="dateRange[1]"
        @change="$emit('date-change')"
      />
    </div>
    <div class="filter-right">
      <button
        v-for="(btn, idx) in timeButtons"
        :key="btn.label"
        class="filter-btn"
        :class="{ active: selectedTimeBtn === idx }"
        @click="$emit('time-btn-click', idx)"
      >
        {{ btn.label }}
      </button>
    </div>
  </div>
</template>

<script setup lang="ts">
interface TimeButton {
  label: string;
  range: [string, string];
}

interface Props {
  timeButtons: TimeButton[];
  selectedTimeBtn: number;
  dateRange: [string, string];
}

defineProps<Props>();
defineEmits<{
  'time-btn-click': [idx: number];
  'date-change': [];
}>();
</script>

<style scoped>
.filter-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fff;
  padding: 22px 36px;
  border-radius: 20px;
  margin-bottom: 36px;
  box-shadow: 0 6px 32px 0 rgba(0, 0, 0, 0.06);
}

.filter-label {
  font-weight: 700;
  color: #222;
  margin-right: 12px;
  font-size: 17px;
}

.filter-left {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 16px;
  color: #666;
}

.date-input {
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 16px;
  background: #fafbfc;
  transition: border 0.2s;
}

.date-input:focus {
  border: 1.5px solid #1890ff;
  outline: none;
}

.filter-right {
  display: flex;
  gap: 16px;
}

.filter-btn {
  background: #f2f4f8;
  border: none;
  border-radius: 8px;
  padding: 10px 32px;
  font-size: 16px;
  color: #666;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.2s, color 0.2s;
  box-shadow: 0 2px 6px 0 rgba(0, 0, 0, 0.03);
}

.filter-btn.active,
.filter-btn:hover {
  background: #1890ff;
  color: #fff;
}
</style> 